
app.controller('detailReportCtrl', ['$scope', function ($scope) {
	var needNewPagination = true;
	$("#date-1").val(""); $("#date-2").val("");
	var reportType = 1;
	lookDetail($("#date-1").val(), $("#date-2").val(), 1);
	
	//我的举报记录
	$("#my-report").click(function() {
		reportType = 1;
		$("#date-1").val(""); $("#date-2").val("");
		needNewPagination = true;
		lookDetail($("#date-1").val(), $("#date-2").val(), 1);
		$("#my-report .tx-span").css("border-bottom-color", "#36CD40");
        $("#be-reported .tx-span").css("border-bottom-color", "#36CD40");
		$("#title-tr").css("color", "#36CD40");
    });
	//我的被举报记录
	$("#be-reported").click(function() {
		reportType = 2;
		$("#date-1").val(""); $("#date-2").val("");
		needNewPagination = true;
		lookDetail($("#date-1").val(), $("#date-2").val(), 1);
		$("#be-reported .tx-span").css("border-bottom-color", "#FF4400");
        $("#my-report .tx-span").css("border-bottom-color", "#FF4400");
		$("#title-tr").css("color", "#FF4400");
    });
	
	$("#sel-date").click(function() {
		needNewPagination = true;
		lookDetail($("#date-1").val(), $("#date-2").val(), 1);
    });
	
	function lookDetail(startTime, endTime, pageNo) {		
		var param = {
			reportType: reportType,
			startTime: startTime,
			endTime: endTime,
			pageNo: pageNo,
			pageCount: 10,
		};
		AQ.callAQ("getReportDetail.do", param, function(result) {
			var data = [];
			for (var i = 1; i < result.length; ++i) {
				if(reportType == 1 && result[i].state == 1) {
					result[i].cancelShow = true;
				} else if(reportType == 2 && result[i].state == 1) {
					result[i].cancelShow = false;
				}
				
				if(result[i].state == 2) 		result[i].state = "已处理：审核通过";
				else if(result[i].state == 3) 	result[i].state = "已处理：审核未通过";
				else if(result[i].state == 1)	result[i].state = "待处理";
				else if(result[i].state == 0)	result[i].state = "已撤销";
				
				if(result[i].reportCate == 110101)		result[i].reportCate = "不改价";
				else if(result[i].reportCate == 110201)	result[i].reportCate = "虚假付款";
				else if(result[i].reportCate == 110202)	result[i].reportCate = "不按要求处理任务";
				else if(result[i].reportCate == 110203)	result[i].reportCate = "使用淘宝客等付款";
				else if(result[i].reportCate == 110301)	result[i].reportCate = "恶意诈骗";
				else if(result[i].reportCate == 110401)	result[i].reportCate = "其它";
				else if(result[i].reportCate == 110501)	result[i].reportCate = "协商取消任务";
				else 									result[i].reportCate = "未知";
				
				result[i].userName = reportType == 1 ? result[i].reportedUserName : result[i].reportUserName;
				data.push(result[i]);
			}
			$scope.$apply(function () {
				$scope.listData = data;
				if(pageNo == 1 && needNewPagination) {	//创建分页
					var num_entries = result[0].count;
					Utils.newPagination("Pagination", num_entries, function(page_index, jq) {
						if(page_index == 0 && needNewPagination) {
							needNewPagination = false;
							return;
						}
						lookDetail($("#date-1").val(), $("#date-2").val(), page_index+1);
					});
				}
			});
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
	}
	
	/**
	 * 撤销举报
	 */
	$scope.cancelReport = function(id) {
		Utils.checkDialog("确定要撤销举报吗？", "确定" ,"返回", function() {
			var param = {
					id: id,
					handleResult: "举报方自己撤销任务投诉",
				};
				AQ.callAQ("cancelReport.do", param, function(result) {
					lookDetail($("#date-1").val(), $("#date-2").val(), 1);
				}, function(err, code) {
					Utils.msgDialog(err + "["+ code +"]");
				});
		}, function() {});
	};
	
	$scope.dialogRead = function(content, title) {
		$("#read-dialog").each(function(index, element) {
			$(element).remove();
		});
		var html = '<div id="read-dialog" style="width:750px; height:400px; overflow:auto;">'
			+ content +'</div>';
		var d = dialog({
			fixed: true,
			zIndex: 999999999,
			title: '投诉举报：' + title,
			content: html,
			okValue: '返回',
			ok: function () {}
		});
		d.width(750);
		d.height(400);
		d.showModal();
	};
	

}]);
